"use strict";
cc._RF.push(module, '5f1fcPcCMRCMY8pXSndD+Cl', 'UIOver');
// script/ui/UIOver.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var GameManager_1 = require("../game/GameManager");
var Constants_1 = require("../libs/Constants");
var GameData_1 = require("../libs/GameData");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var UIOver = /** @class */ (function (_super) {
    __extends(UIOver, _super);
    function UIOver() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.win = null;
        _this.fail = null;
        _this.normal = null;
        _this.rewardNum = 0;
        return _this;
    }
    UIOver.prototype.start = function () {
        this.rewardNum = Math.round(GameData_1.default.instance.playScore / 10);
        this.win.active = false;
        this.fail.active = false;
        this.normal.active = false;
        if (GameData_1.default.instance.gameModel) {
            if (GameData_1.default.instance.playScore >= Constants_1.default.StageInfo[GameData_1.default.instance.gameStage - 1].winscore) {
                this.refreshWinNode();
            }
            else {
                this.refreshFailNode();
            }
        }
        else {
            this.refreshNormalNode();
        }
    };
    UIOver.prototype.refreshWinNode = function () {
        this.win.active = true;
        GameData_1.default.instance.gameStage++;
        if (GameData_1.default.instance.gameStage > Constants_1.default.StageInfo.length) {
            GameData_1.default.instance.gameStage = 1;
        }
        var num1 = this.win.getChildByName("Num").getComponent(cc.Label);
        var num2 = this.win.getChildByName("SignleGet").getChildByName("num").getComponent(cc.Label);
        num1.string = this.rewardNum.toString();
        num2.string = this.rewardNum.toString();
    };
    UIOver.prototype.refreshFailNode = function () {
        this.fail.active = true;
        var num1 = this.fail.getChildByName("Num").getComponent(cc.Label);
        var num2 = this.fail.getChildByName("SignleGet").getChildByName("num").getComponent(cc.Label);
        num1.string = this.rewardNum.toString();
        num2.string = this.rewardNum.toString();
    };
    UIOver.prototype.refreshNormalNode = function () {
        this.normal.active = true;
    };
    UIOver.prototype.onGet = function (event, customEventData) {
        var para = parseInt(customEventData);
        GameData_1.default.instance.playGold += this.rewardNum * para;
        this.recordScore();
        GameManager_1.default.instace.backMain();
    };
    UIOver.prototype.onSure = function () {
        this.recordScore();
        GameManager_1.default.instace.backMain();
    };
    UIOver.prototype.recordScore = function () {
        if (GameData_1.default.instance.gameModel) {
            GameData_1.default.instance.playScores.push(GameData_1.default.instance.playScore);
            GameData_1.default.instance.playScores.sort(function (a, b) { return b - a; });
        }
        else {
            GameData_1.default.instance.playCrazyScores.push(GameData_1.default.instance.playScore);
            GameData_1.default.instance.playCrazyScores.sort(function (a, b) { return b - a; });
        }
        GameData_1.default.instance.saveData();
    };
    __decorate([
        property(cc.Node)
    ], UIOver.prototype, "win", void 0);
    __decorate([
        property(cc.Node)
    ], UIOver.prototype, "fail", void 0);
    __decorate([
        property(cc.Node)
    ], UIOver.prototype, "normal", void 0);
    UIOver = __decorate([
        ccclass
    ], UIOver);
    return UIOver;
}(cc.Component));
exports.default = UIOver;

cc._RF.pop();